var proxy = require('http-proxy-middleware');
var express = require('express');
var app = express();
var fs = require('fs');
 
app.use(express.static('public'));
// app.use('/modules', proxy({
// 	target: 'http://182.61.28.147:8080',
// 	changeOrigin: true,
// 	pathRewrite: {
//     '^/modules' : '/modules'
//   },
// }));
 

app.get('/readData/:fileName', function (req, res) {
	// 异步读取
	let filePath = 'data/' + req.params.fileName + '.json';
	fs.readFile(filePath, function (err, data) {
	   if (err) {
	       return console.error(err);
	   }
  	res.send({ errorNum: 0, data: data.toString() });
	});
})
 
var server = app.listen(8091, function () {
 
  var host = server.address().address
  var port = server.address().port
 
  console.log("应用实例，访问地址为 http://%s:%s", host, port)
 
})